﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using AssetFrame.BP;
using AssetFrame.Message;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace AppServer.Controllers.Asset
{
    [Route("api/[controller]")]
    [ApiController]
    public class SysAssetA1Controller : SysControllerBase
    {
        // 字段配置
        // POST: api/SysAssetA1
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action == null ? "Get" : data.Action;
            string rtstr = "";
            //得到列表
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            if (Action == "Save")
            {
                rtstr = Save(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到字段配置列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data)
        {
            MsQuery msq = new MsQuery();
            try
            {
                //分类id
                JObject postdata = JObject.FromObject(data.data);
                JObject search = JObject.FromObject(postdata["search"]);
                try
                {
                    if (!string.IsNullOrEmpty(search["SYS_ASSET_A1_40"].ToString()))
                    {
                        msq.strquery += " and SYS_ASSET_A1_40 = '" + search["SYS_ASSET_A1_40"].ToString() + "'";
                    }
                }
                catch { }
                try
                {
                    if (!string.IsNullOrEmpty(search["SYS_ASSET_A1_160"].ToString())) {
                    msq.strquery += " and SYS_ASSET_A1_160 like '%"+ search["SYS_ASSET_A1_160"].ToString() + "%'";
                    }
                }
                catch { }
                try
                {
                    if (!string.IsNullOrEmpty(search["SYS_ASSET_A1_50"].ToString()))
                    {
                        msq.strquery += " and SYS_ASSET_A1_50 like '%" + search["SYS_ASSET_A1_50"].ToString() + "%'";
                    }
                }
                catch { }
                try
                {
                    if (!string.IsNullOrEmpty(search["SYS_ASSET_A1_60"].ToString()))
                    {
                        msq.strquery += " and SYS_ASSET_A1_60 like '%" + search["SYS_ASSET_A1_60"].ToString() + "%'";
                    }
                }
                catch { }
                try
                {
                    if (!string.IsNullOrEmpty(search["SYS_ASSET_A1_140"].ToString()))
                    {
                        msq.strquery += " and SYS_ASSET_A1_140 like '%" + search["SYS_ASSET_A1_140"].ToString() + "%'";
                    }
                }
                catch { }
            } catch { }
            msq.obj1 = GetSessionUser();
            DataTable dt = ((DataSet)new BLLsys_asset_a1().Getsys_asset_a1ByQuery(msq).data).Tables[0];
            return JArray.FromObject(dt).ToString();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Save(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            Mssys_asset_a1 ms = Mssys_asset_a1.parse<Mssys_asset_a1>(postdata);
            //ms8.System_8_50 = "1";
            MsReturned rt = new BLLsys_asset_a1().Savesys_asset_a1(ms);
            return JObject.FromObject(rt).ToString();
        }
    }
}